//
//  AppDelegate.m
//  Vision
//
//  Created by dllo on 16/3/10.
//  Copyright © 2016年 yue_zhang. All rights reserved.
//

#import "AppDelegate.h"
// 每日精选
#import "SelectedViewController.h"
// 发现
#import "DiscViewController.h"
// 热门
#import "HotViewController.h"

@interface AppDelegate ()<UITabBarControllerDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    SelectedViewController *selectedVC = [[SelectedViewController alloc] initWithNibName:NSStringFromClass([SelectedViewController class]) bundle:nil];
    UINavigationController *selectedNaVC = [[UINavigationController alloc] initWithRootViewController:selectedVC];
    selectedNaVC.tabBarItem = [[UITabBarItem alloc] init];
    
    DiscViewController *discVC = [[DiscViewController alloc] initWithNibName:NSStringFromClass([DiscViewController class]) bundle:nil];
    UINavigationController *discNaVC = [[UINavigationController alloc] initWithRootViewController:discVC];
    discNaVC.tabBarItem = [[UITabBarItem alloc] init];

    HotViewController *hotVC = [[HotViewController alloc] initWithNibName:NSStringFromClass([HotViewController class]) bundle:nil];
    UINavigationController *hotNaVC = [[UINavigationController alloc] initWithRootViewController:hotVC];
    hotNaVC.tabBarItem = [[UITabBarItem alloc] init];

    UITabBarController *tabBarCtrl = [[UITabBarController alloc] init];
    tabBarCtrl.viewControllers = @[selectedNaVC, discNaVC, hotNaVC];
    tabBarCtrl.delegate = self;
    
    self.window.rootViewController = tabBarCtrl;
    return YES;
}

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController*)viewController {
    CATransition *transition = [CATransition animation];
    // 设置一下动画类型
    transition.type = @"fade";
    /** type
     *
     *  各种动画效果  其中除了'fade', 'moveIn', 'push' , 'reveal' ,其他属于私有的API.
     *  ↑↑↑上面四个可以分别使用'kCATransitionFade', 'kCATransitionMoveIn', 'kCATransitionPush', 'kCATransitionReveal'来调用.
     *  @"cube"                     立方体翻滚效果
     *  @"moveIn"                   新视图移到旧视图上面
     *  @"reveal"                   显露效果(将旧视图移开,显示下面的新视图)
     *  @"fade"                     交叉淡化过渡(不支持过渡方向)             (默认为此效果)
     *  @"pageCurl"                 向上翻一页
     *  @"pageUnCurl"               向下翻一页
     *  @"suckEffect"               收缩效果，类似系统最小化窗口时的神奇效果(不支持过渡方向)
     *  @"rippleEffect"             滴水效果,(不支持过渡方向)
     *  @"oglFlip"                  上下左右翻转效果
     *  @"rotate"                   旋转效果
     *  @"push"
     *  @"cameraIrisHollowOpen"     相机镜头打开效果(不支持过渡方向)
     *  @"cameraIrisHollowClose"    相机镜头关上效果(不支持过渡方向)
     */
    // 设置动画时长
    transition.duration = 0.2;
    transition.repeatCount = 1;
    [self.window.layer addAnimation:transition forKey:@"trasition"];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
